package com.longrise.android.byjk.plugins.tabthird;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by callxkj on 2017/3/10.
 * 我的页面 常用工具类型中的rcv的 adapter
 */

public class MineRcvitem2Adapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {
    private List<EntityBean> mBeans = new ArrayList<>();
    private OnMineItem2ClickListener mOnMineItem2ClickListener;

    public MineRcvitem2Adapter() {
        super(R.layout.item_mine_item2_recycle, null);
    }

    public void setDatas(EntityBean[] beans) {
        if (beans == null) {
            return;
        }
        mBeans.clear();
        for (EntityBean bean : beans) {
            mBeans.add(bean);
        }
        setNewData(mBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, EntityBean item) {
        String picpath = item.getString("picpath");
        final String showname = item.getString("showname");
        final String uniqueid = item.getString("uniqueid");
        final String linkedtype = item.getString("linkedtype");
        final String linkedurl = item.getString("linkedurl");
        final String fullurl = item.getString("fullurl");

        View convertView = helper.getConvertView();
        ImageView iv = (ImageView) convertView.findViewById(R.id.mine_fragment_item2_rcv_iv);
        Glide.with(AppUtil.getContext()).load(picpath).into(iv);
        helper.setText(R.id.mine_fragment_item2_rcv_tv, showname);
        helper.setVisible(R.id.mine_fragment_item2_point2, false); //红点 默认隐藏

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnMineItem2ClickListener != null) {
                    mOnMineItem2ClickListener.onClick(uniqueid, linkedtype, showname, linkedurl, fullurl);
                }
            }
        });
    }

    public void setOnMineItem2ClickListener(OnMineItem2ClickListener listener) {
        this.mOnMineItem2ClickListener = listener;
    }

    public interface OnMineItem2ClickListener {
        void onClick(String uniqueid, String linkedtype, String showname, String linkedurl,
                     String fullurl);
    }
}
